<template>
  <div class="mod-user">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <div class="seacrhMoney">
        <el-form-item>
          <div class="balance-searchMoney">
            订单编号
            <el-input class="input" v-model="dataForm.userName" placeholder="请输入订单编号"></el-input>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="balance-searchMoney">
            支付单号
            <el-input class="input" v-model="paySerialId" placeholder="请输入支付单号"></el-input>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="balance-searchMoney">
            支付时间
            <el-date-picker v-model="value1" :clearable='false' type="daterange" value-format="yyyy-MM-dd HH:mm:ss" style="width:240px" class="input" start-placeholder="开始日期" end-placeholder="结束日期">
            </el-date-picker>
          </div>
        </el-form-item>
        <!-- <el-form-item>
          <div class="balance-searchMoney">
            物业账单周期
            <el-date-picker v-model="value2" type="monthrange" @change="TimeYue" class="input" value-format="yyyy-MM" start-placeholder="开始月份" end-placeholder="结束月份">
            </el-date-picker>
          </div>
        </el-form-item> -->
        <div>
          <el-form-item>
            <div class="balance-searchMoney">
              订单类型
              <el-select v-model="ordertype" filterable placeholder="请选择">
                <el-option v-for="item in options1" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </div>
          </el-form-item>
          <el-form-item>
            <div class="balance-searchMoney">
              支付方式
              <el-select v-model="value3" filterable placeholder="请选择">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </div>
          </el-form-item>
          <el-form-item>
            <div class="balance-searchMoney">
              结算状态
              <el-select v-model="settlement" filterable placeholder="请选择">
                <el-option v-for="item in options2" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </div>
          </el-form-item>
        </div>
        <el-form-item>
          <div class="balance-searchMoney">
            收费单位
            <el-select v-model="legalAccountCodes" filterable placeholder="请选择">
              <el-option v-for="item in charges" :key="item.legalAccountCode" :label="item.legalCompanyName" :value="item.legalAccountCode">
              </el-option>
            </el-select>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="balance-searchMoney">
            用户地址
            <el-input class="input" v-model="dataForm.communityInfos" placeholder="请输入用户地址"></el-input>
          </div>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="demand">查询</el-button>
          <el-button type="primary" @click="empty">清空</el-button>
        </el-form-item>
        <!-- <el-form-item>
          <div class="balance-searchMoney">
            法人公司
            <el-select
              v-model="value4"
              clearable
              @change="cityCode"
              filterable
              placeholder="请选择"
            >
              <el-option
                v-for="item in city"
                :key="item.legalAccountCode"
                :label="item.legalCompanyName"
                :value="item.legalAccountCode"
              >
              </el-option>
            </el-select>
          </div>
        </el-form-item> -->
      </div>
    </el-form>

    <!-- 表格 -->
    <div class="export">
      <div style="display: flex; justify-content: flex-end;margin-bottom:10px;">
        <el-button type="primary" @click="exportExcel()">导出Excel</el-button>
      </div>
      <el-table :data="dataList" v-loading="dataListLoading" element-loading-text="数据加载中" element-loading-spinner="el-icon-loading" element-loading-custom-class="loading_color" style="width: 100%;">
        <template slot="empty">
          <img class="machine" src="../../assets/img/machine.svg" alt="" />
          <div style="font-size: 14px; text-align: center">暂无数据</div>
        </template>
        <!-- <el-table-column prop="" width="130" header-align="center" align="center" label="订单联系人">
          <template slot-scope="scope">
            <div size="small" type="danger">
              {{ scope.row.memberName }} /
              {{ scope.row.memberPhone }}
            </div>
          </template>
        </el-table-column> -->
        <el-table-column prop="orderNo" width="120" header-align="center" align="center" label="订单编号">
          <template slot-scope="scope">
            <div size="small" type="danger">
              <div v-if="scope.row.billType == 1" size="small">{{scope.row.paySerialNbr}}</div>
              <div v-if="scope.row.billType == 3" size="small">{{ scope.row.orderNo}}</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="paySerialId" header-align="center" align="center" label="支付单号" width="100">
        </el-table-column>
        <el-table-column prop="billType" header-align="center" align="center" label="订单类型" width='100'>
          <template slot-scope="scope">
            <div size="small" type="danger">
              <div v-if="scope.row.billType == 1" size="small">物业费</div>
              <div v-if="scope.row.billType == 2" size="small">有偿工单</div>
              <div v-if="scope.row.billType == 3" size="small">到家服务</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="dealType" header-align="center" align="center" label="交易类型" width='100'>
          <template slot-scope="scope">
            <div v-if="scope.row.dealType == 0" size="small">收款</div>
            <div v-if="scope.row.dealType == 1" size="small">退款</div>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="dealDes" width="100" header-align="center" align="center" label="交易描述">
        </el-table-column> -->
        <!-- <el-table-column prop="" header-align="center" align="center" label="交易时间" width='140'>
          <template slot-scope="scope">
            <div size="small" type="danger">
              {{ scope.row.startBillCycle }} -
              {{ scope.row.endBillCycle }}
            </div>
          </template>
        </el-table-column> -->
        <el-table-column prop="dealDes" width="100" header-align="center" align="center" label="交易描述">
        </el-table-column>
        <el-table-column prop="paymentFee" header-align="center" align="center" label="交易金额" width='100'>
          <template slot-scope="scope">
            <div>{{ scope.row.paymentFee| MoneyFormat}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="serviceCharge" header-align="center" align="center" label="手续费(元)" width="100">
          <template slot-scope="scope">
            <div>{{ scope.row.serviceCharge | MoneyFormat}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="recordedAmount" header-align="center" align="center" label="入账金额(元)" width="100">
          <template slot-scope="scope">
            <div>{{ scope.row.recordedAmount | MoneyFormat}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="" header-align="center" align="center" label="支付方式">
          <template slot-scope="scope">
            <div v-if="scope.row.paymentMethod == 1" size="small">微信</div>
            <div v-if="scope.row.paymentMethod == 2" size="small">支付宝</div>
            <div v-if="scope.row.paymentMethod == 3" size="small">云闪付</div>
            <div v-if="scope.row.paymentMethod == 4" size="small">快捷支付</div>
          </template>
        </el-table-column>
        <el-table-column prop="paymentTime" header-align="center" align="center" label="支付时间" width="100">
        </el-table-column>
        <el-table-column prop="platformType" header-align="center" align="center" label="支付终端">
        </el-table-column>
        <el-table-column prop="legalCompanyName" header-align="center" align="center" label="收费单位" width="100">
        </el-table-column>
        <el-table-column prop="userAddress" header-align="center" align="center" label="用户地址" width='140'>
        </el-table-column>
        <el-table-column prop="status" header-align="center" align="center" label="结算状态">
          <template slot-scope="scope">
            <div v-if="scope.row.settlementStatus === 0" size="small" type="danger" class="blueMoney">
              未结算
            </div>
            <div v-else size="small" class="greenMoney">已结算</div>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="serviceCharge" header-align="center" align="center" label="手续费(元)">
        </el-table-column> -->
        <!-- <el-table-column prop="recordedAmount" header-align="center" align="center" label="入账金额(元)">
        </el-table-column> -->
        <!-- <el-table-column prop="paySerialNbr" width="130" header-align="center" align="center" label="四格缴费编号" :render-header="fourGrid">
        </el-table-column> -->
        <!-- <el-table-column prop="" header-align="center" align="center" label="账单类型" :render-header="renderHeader" width='100'
          <template slot-scope="scope">
            <div size="small" type="danger">
              <div v-if="scope.row.billType == 1" size="small">物业费</div>
              <div v-if="scope.row.billType == 2" size="small">有偿工单</div>
            </div>
          </template>
        </el-table-column> -->
        <!-- <el-table-column prop="" width="120" header-align="center" align="center" label="账单月份">
          <template slot-scope="scope">
            <div size="small" type="danger">
              {{ scope.row.startBillCycle }} -
              {{ scope.row.endBillCycle }}
            </div>
          </template>
        </el-table-column> -->
        <!-- <el-table-column prop="totalFee" header-align="center" align="center" label="账单金额(元)">
          <template slot-scope="scope">
            <div>{{ scope.row.totalFee | MoneyFormat }}</div>
          </template>
        </el-table-column> -->
        <!-- <el-table-columnprop="paymentFee"header-align="center"align="center"label="实际支付金额(元)">
          </el-table-column> -->
        <!-- <el-table-column prop="totalFee" header-align="center" align="center" label="支付费率">
          <template slot-scope="scope">
            <div>{{ scope.row.payRate  }}%</div>
          </template>
        </el-table-column> -->
        <!-- <el-table-column prop="communityInfo" header-align="center" align="center" label="归属项目">
        </el-table-column> -->
      </el-table>
    </div>

    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

  </div>
</template>

<script>
export default {
  data () {
    return {
      legalAccountCode: "", //法人公司编码
      cycleNo: "", //账单单号
      endBillCycle: "", //结束账期
      endPaymentTime: "", //结束支付时间
      orderNo: "", //订单编号
      paySerialId: '',
      startBillCycle: "", //开始账期
      startPaymentTime: "", //开始支付时间
      paymentMethod: "", //订单编号支付方式：1-微信,2-支付宝,3-云闪付,4-快捷支付
      dataForm: {
        userName: "",
        communityInfos: ""
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
      value1: "",
      value2: "",
      value3: "",
      value4: "",
      ordertype: '',
      settlement: '',
      legalAccountCodes: '',
      city: [],
      charges: [],
      options: [
        {
          value: "1",
          label: "微信",
        },
        {
          value: "2",
          label: "支付宝",
        },
        {
          value: "3",
          label: "云闪付",
        },
        {
          value: "4",
          label: "快捷支付",
        },
      ],
      options1: [
        {
          value: "1",
          label: "物业费",
        },
        {
          value: "2",
          label: "有偿工单",
        },
        {
          value: "3",
          label: "到家服务",
        }
      ],
      //结算
      options2: [
        {
          value: "0",
          label: "未结算",
        },
        {
          value: "1",
          label: "已结算",
        }
      ],
    };
  },
  activated () {
    this.cycleNo = this.$route.query.cycleNo;
    this.cycleNos = this.$route.query.cycleNos;
    this.userCode = localStorage.getItem("userCode");
    this.getDataList();
    this.cityList();
    this.sava()
  },
  methods: {
    // 表格头部提示事件
    fourGrid (h, { column }) {
      return h("span", [
        h("span", column.label),
        h(
          "el-tooltip",
          {
            props: {
              effect: "dark",
              content: "四格缴费的唯一编号，可用于跟四格ERP对账",
              placement: "top",
            },
          },
          [
            h("i", {
              class: "el-icon-question",
              style: "color:#000;margin-left:5px;",
            }),
          ],
          {
            content: "四格缴费的唯一编号，可用于跟四格ERP对账",
          }
        ),
      ]);
    },
    // 表格头部提示事件
    renderHeader (h, { column }) {
      return h("span", [
        h("span", column.label),
        h(
          "el-tooltip",
          {
            props: {
              effect: "dark",
              content: "包含物业费和有偿工单",
              placement: "top",
            },
          },
          [
            h("i", {
              class: "el-icon-question",
              style: "color:#000;margin-left:5px;",
            }),
          ],
          {
            content: "包含物业费和有偿工单",
          }
        ),
      ]);
    },
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("cassadmin/v1/settlementBill/paymentList"),
        method: "get",
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          legalAccountCode: this.legalAccountCode,
          cycleNo: this.cycleNo,
          cycleNos: this.cycleNos,
          paySerialId: this.paySerialId,
          endBillCycle: this.endBillCycle,
          endPaymentTime: this.endPaymentTime,
          orderNo: this.orderNo,
          startBillCycle: this.startBillCycle,
          startPaymentTime: this.startPaymentTime,
          paymentMethod: this.paymentMethod,
        }),
      }).then(({ data }) => {
        if (data.success == 1) {
          this.dataList = data.data.list;
          this.totalPage = data.data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 城市列表
    // 获取数据列表
    cityList () {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl(
          "cassadmin/legalCompany/getByCurrentFinanceCode"
        ),
        method: "get",
        params: this.$http.adornParams({}),
      }).then(({ data }) => {
        if (data.success == 1) {
          console.log(data);
          this.city = data.data;
        } else {
          this.$message.error(data.errorMsg);
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("cassadmin/v1/settlementBill/paymentList"),
        method: "get",
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          legalAccountCode: this.legalAccountCodes,
          cycleNo: this.cycleNo,
          cycleNos: this.cycleNos,
          paySerialId: this.paySerialId,
          endBillCycle: this.endBillCycle,
          endPaymentTime: this.value1[1] || '',
          orderNo: this.dataForm.userName,
          startBillCycle: this.startBillCycle,
          startPaymentTime: this.value1[0] || '',
          paymentMethod: this.value3,
          billType: this.ordertype,
          settlementStatus: this.settlement,
          userAddress: this.dataForm.communityInfos
        }),
      }).then(({ data }) => {
        if (data.success == 1) {
          this.dataList = data.data.list;
          this.totalPage = data.data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false
      });
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val;
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("cassadmin/v1/settlementBill/paymentList"),
        method: "get",
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          legalAccountCode: this.legalAccountCodes,
          cycleNo: this.cycleNo,
          cycleNos: this.cycleNos,
          paySerialId: this.paySerialId,
          endBillCycle: this.endBillCycle,
          endPaymentTime: this.value1[1] || '',
          orderNo: this.dataForm.userName,
          startBillCycle: this.startBillCycle,
          startPaymentTime: this.value1[0] || '',
          paymentMethod: this.value3,
          billType: this.ordertype,
          settlementStatus: this.settlement,
          userAddress: this.dataForm.communityInfos
        }),
      }).then(({ data }) => {
        if (data.success == 1) {
          this.dataList = data.data.list;
          this.totalPage = data.data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false
      });
    },
    //查询
    demand () {
      this.pageIndex = 1
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("cassadmin/v1/settlementBill/paymentList"),
        method: "get",
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          legalAccountCode: this.legalAccountCodes,
          cycleNo: this.cycleNo,
          cycleNos: this.cycleNos,
          paySerialId: this.paySerialId,
          endBillCycle: this.endBillCycle,
          endPaymentTime: this.value1[1] || '',
          orderNo: this.dataForm.userName,
          startBillCycle: this.startBillCycle,
          startPaymentTime: this.value1[0] || '',
          paymentMethod: this.value3,
          billType: this.ordertype,
          settlementStatus: this.settlement,
          userAddress: this.dataForm.communityInfos
        }),
      }).then(({ data }) => {
        if (data.success == 1) {
          this.dataList = data.data.list;
          this.totalPage = data.data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false
      });
    },
    //清空
    empty () {
      this.dataForm.userName = ''
      this.value1 = ''
      this.value3 = ''
      this.settlement = ''
      this.ordertype = ''
      this.paySerialId = ''
      this.legalAccountCodes = ''
      this.dataForm.communityInfos = ''
      this.getDataList()
    },
    // 导出excel
    exportExcel () {
      if (this.value1 == '') {
        var end = this.value1
        var start = this.value1
      } else {
        var end = this.value1[1]
        var start = this.value1[0]
      }
      window.location.href =
        `https://api.xstarlife.com/cassadmin/v1/settlementBill/downloadPaymentList?&cycleNo=${this.cycleNo}&endBillCycle=${this.endBillCycle}&endPaymentTime=${end}&orderNo=${this.dataForm.userName}&paySerialId=${this.paySerialId}&startBillCycle=${this.startBillCycle}&startPaymentTime=${start}&paymentMethod=${this.value3}&billType=${this.ordertype}&settlementStatus=${this.settlement}&userAddress=${this.dataForm.communityInfos}&legalAccountCode=${this.legalAccountCodes}`
    },
    // 周期
    // TimeYue (e) {
    //   this.pageIndex = 1;
    //   if (e) {
    //     this.startBillCycle = e[0];
    //     this.endBillCycle = e[1];
    //   } else {
    //     this.startBillCycle = "";
    //     this.endBillCycle = "";
    //   }
    //   this.getDataList();
    // },
    // 城市
    cityCode (e) {
      this.pageIndex = 1;
      this.legalAccountCode = e;
      this.getDataList();
    },
    //收费单位下拉
    sava () {
      this.$http({
        url: this.$http.adornUrl("/cassadmin/v1/billDetail/fetchAllLegalCompany"),
        method: "get",
      }).then(({ data }) => {
        console.log(data, '213123')
        this.charges = data.data
      });
    },
  },
};
</script>
<style scoped>
.balance-searchMoney {
  display: flex;
  align-items: center;
}
.export {
  margin-top: 30px;
  background-color: #fff;
  padding: 20px;
  border-radius: 6px;
}
.input {
  flex: 1;
  margin-left: 5px;
}
</style>
